﻿using CPPEI.EBS.Proxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace CPPEI.ETL.WebApi.EBS
{
    public class EBSReceive : IHttpHandler
    {
        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }

        public void ProcessRequest(HttpContext context)
        {
            EBSResponse ebsResponse = null;
            try
            {
                ebsResponse = new CPPEI.EBS.Proxy.EBSResponse(context.Request);
                Logger.InfoToTag(Library.LogTAG, string.Format("receive ebs event:{0}", ebsResponse.Event));
            }
            catch (Exception ex)
            {
                Logger.ErrorToTag(Library.LogTAG, string.Format("receive ebs error:{0}", ex));
                return;
            }
            
            try
            {
                // 根据event获取task，然后执行task
                CPPEI.ETL.Domain.Services.TaskService taskService = new Domain.Services.TaskService();
                taskService.RunByEvent("System", ebsResponse.Event);
            }
            catch (Exception ex)
            {
                Logger.ErrorToTag(Library.LogTAG, string.Format("taskService.RunByEvent(\"System\", ebsResponse.Event) error:{0}", ex));
            }
            
        }
    }
}
